home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / network / daemons / nfs / nfs-serv.2be / nfs-serv / nfs-server-2.2beta16 / mount_dispatch.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-25  |  3.2 KB  |  138 lines

  1. /*
  2.  * dispatch.c    This file contains the function dispatch table.
  3.  *
  4.  * Authors:    Donald J. Becker, <becker@super.org>
  5.  *        Rick Sladkey, <jrs@world.std.com>
  6.  *        Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
  7.  *        Olaf Kirch, <okir@monad.swb.de>
  8.  *
  9.  *        This software may be used for any purpose provided
  10.  *        the above copyright notice is retained.  It is supplied
  11.  *        as is, with no warranty expressed or implied.
  12.  */
  13.  
  14. #include "mountd.h"
  15. #include "rpcmisc.h"
  16.  
  17. /*
  18.  * These are the global variables that hold all argument and result data.
  19.  */
  20. union argument_types     argument;
  21. union result_types    result;
  22.  
  23. /*
  24.  * This is a dispatch table to simplify error checking,
  25.  * and supply return attributes for NFS functions.
  26.  */
  27.  
  28. #ifdef __STDC__
  29. #define CONCAT(a,b)    a##b
  30. #define CONCAT3(a,b,c)    a##b##c
  31. #define STRING(a)    #a
  32. #else
  33. #define CONCAT(a,b)    a/**/b
  34. #define CONCAT3(a,b,c)    a/**/b/**/c
  35. #define STRING(a)    "a"
  36. #endif
  37.  
  38. #define table_ent(res_type, arg_type, funct) {            \
  39.     sizeof(res_type), sizeof(arg_type),            \
  40.     (xdrproc_t) CONCAT(xdr_,res_type),            \
  41.     (xdrproc_t) CONCAT(xdr_,arg_type),            \
  42.     (void *(*)()) CONCAT3(mountproc_,funct,_1_svc),        \
  43.     STRING(funct), CONCAT(pr_,arg_type)            \
  44. }
  45.  
  46. #define nil    void
  47. #define xdr_nil    xdr_void
  48. #define pr_nil    pr_void
  49. #define pr_char    pr_void
  50.  
  51. struct dispatch_entry {
  52.     int        res_size, arg_size;    /* sizeof the res/arg structs    */
  53.     xdrproc_t    xdr_result;
  54.     xdrproc_t    xdr_argument;
  55.     void    *(*funct)();        /* function handler        */
  56.     char    *name;            /* name of function        */
  57.     char    *(*log_print)();    /* ptr to debug handler        */
  58. };
  59.  
  60. static _PRO( char *pr_void, (void)                    );
  61. static _PRO( char *pr_dirpath, (dirpath *argp)                );
  62.  
  63. static struct dispatch_entry dtable[] = {
  64.     table_ent(nil,nil,null),            /* NULL */
  65.     table_ent(fhstatus,dirpath,mnt),        /* MNT */
  66.     table_ent(mountlist,void,dump),            /* DUMP */
  67.     table_ent(void,dirpath,umnt),            /* UMNT */
  68.     table_ent(void,void,umntall),            /* UMNTALL */
  69.     table_ent(exports,void,export),            /* EXPORT */
  70.     table_ent(exports,void,exportall),        /* EXPORTALL */
  71. };
  72.  
  73.  
  74. /*
  75.  * The main dispatch routine.
  76.  */
  77. void mount_dispatch(rqstp, transp)
  78. struct svc_req *rqstp;
  79. SVCXPRT *transp;
  80. {
  81.     unsigned int        proc_index;
  82.     struct dispatch_entry    *dent;
  83.     union result_types    *resp;
  84.  
  85.     proc_index = rqstp->rq_proc;
  86.     _rpcsvcdirty = 1;
  87.  
  88.     if (proc_index >= (sizeof(dtable) / sizeof(dtable[0]))) {
  89.         svcerr_noproc(transp);
  90.         goto done;
  91.     }
  92.     dent = &dtable[proc_index];
  93.  
  94.     memset(&argument, 0, dent->arg_size);
  95.     if (!svc_getargs(transp, dent->xdr_argument, &argument)) {
  96.         svcerr_decode(transp);
  97.         goto done;
  98.     }
  99.     /* Clear the result structure. */
  100.     memset(&result, 0, dent->res_size);
  101.  
  102.     /* Log the call. */
  103.     if (logging_enabled(D_CALL))
  104.         log_call(rqstp, dent->name, dent->log_print(&argument));
  105.  
  106.     /* Do the function call itself. */
  107.     resp = (*dent->funct) (&argument, rqstp);
  108.  
  109.     if (!svc_sendreply(transp, dent->xdr_result, (caddr_t) resp)) {
  110.         svcerr_systemerr(transp);
  111.     }
  112.     if (!svc_freeargs(transp, dent->xdr_argument, &argument)) {
  113.         dprintf(L_ERROR, "unable to free RPC arguments, exiting\n");
  114.         exit(1);
  115.     }
  116.  
  117. done:
  118.     _rpcsvcdirty = 0;
  119.     if (need_reinit) {
  120.         reinitialize(0);
  121.     }
  122. }
  123.  
  124. /*
  125.  * Functions for debugging output.
  126.  */
  127. static char *pr_void()
  128. {
  129.     return ("");
  130. }
  131.  
  132. static char *pr_dirpath(argp)
  133. dirpath *argp;
  134. {
  135.     return (*argp);
  136. }
  137.  
  138.